using System;
using System.Collections.Generic;
using System.Linq;
using Nop.Core.Domain.Discounts;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Security;
using Nop.Core.Domain.Seo;
using Nop.Core.Domain.Media;

namespace Nop.Core.ApiDataModel
{
    /// <summary>
    /// Represents a category MVC API DataModel.
    /// </summary>
	public partial class Category
    {
        /// <summary>
        /// Gets or sets the name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the description
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the category identifier
        /// </summary>
        public int CategoryId { get; set; }

        /// <summary>
        /// Gets or sets the parent category identifier
        /// </summary>
        public int ParentCategoryId { get; set; }

        /// <summary>
        /// Gets or sets the picture identifier
        /// </summary>
        public string PictureUrl { get; set; }
        
        public int DisplayOrder { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether to show the category on home page
        /// </summary>
        public bool ShowOnHomePage { get; set; }

		public SlideShowModel SlideShow { get; set; }

        public ICollection<Category> SubCategories { get; set; }

        public Category(Nop.Core.Domain.Catalog.Category category)
        {
            this.Name = category.Name;
            this.Description = category.Description;
            this.ParentCategoryId = category.ParentCategoryId;            
            this.CategoryId = category.Id;
            this.ShowOnHomePage = category.ShowOnHomePage;
            this.DisplayOrder = category.DisplayOrder;
            this.SubCategories = new List<Nop.Core.ApiDataModel.Category>();
			if (category.SlideShow!=null)
				this.SlideShow = new SlideShowModel(category.SlideShow);
        }
    }

	public class SlideShowModel
	{
		public double Height { get; set; }

		public double Width { get; set; }

		public double AutoSlideInterval { get; set; }

		public PictureLinkCollectionModel PictureLinkCollection { get; set; }

		public SlideShowModel(Slideshow slideshow)
		{			
			this.Height = slideshow.Height;
			this.Width = slideshow.Width;
			this.AutoSlideInterval = slideshow.AutoSlideInterval.HasValue ? slideshow.AutoSlideInterval.Value : 0;
			this.PictureLinkCollection = new PictureLinkCollectionModel(slideshow.PictureLinkCollection);
		}

	}

	public class PictureLinkCollectionModel
	{
		public string SystemName { get; set; }

		public ICollection<PictureLinkModel> PictureLinks { get; set; }

		public PictureLinkCollectionModel(PictureLinkCollection collection)
		{
			this.SystemName = collection.SystemName;
			this.PictureLinks = new List<PictureLinkModel>();
		    
			foreach (var link in collection.PictureLinks.OrderBy(p=>p.DisplayOrder))
			{
				PictureLinks.Add(new PictureLinkModel(link));
			}
		}
	}

	public class PictureLinkModel
	{
		public int PictureId { get; set; }
		public virtual string Alt { get; set; }
		public virtual int DisplayOrder { get; set; }
		public virtual string DisplayText { get; set; }
		public virtual string SystemName { get; set; }
		public virtual string PictureUrl { get; set; }
		public virtual string Url { get; set; }

		public PictureLinkModel(PictureLink link)
		{
			this.PictureId = link.PictureId;
			this.Alt = link.Alt;
			this.DisplayOrder = link.DisplayOrder;
			this.DisplayText = link.DisplayText;
			this.SystemName = link.SystemName;
			this.Url = link.Url;
		}
	}
}
